<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>6</li>
        <li>7</li>
    </ul>
    <script>
        let lis = document.querySelectorAll('li')
        lis.forEach((item,index)=>{
            if(index%2==0){
                item.style.background = 'red'
            }else{
                item.style.background = 'yellow'
            }
        })
    </script>
</body>
</html>